/** @file    GardenZone.cpp
 *  @author  Alessandro Polo
 *  @version $Id: GardenZone.cpp 2893 2010-08-12 02:26:01Z alex $
 *  @brief
 * File containing methods for the wosh::building::GardenZone class.
 * The header for this class can be found in GardenZone.h, check that file
 * for class description.
 ****************************************************************************/
/* Copyright (c) 2007-2010, WOSH - Wide Open Smart Home 
 * by Alessandro Polo - OpenSmartHome.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the OpenSmartHome.com WOSH nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY Alessandro Polo ''AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL Alessandro Polo BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ****************************************************************************/
 
 #include <framework/building/GardenZone.h>
 #include <framework/building/AppliancesCommon.h>
 #include <framework/building/Sprinkler.h>
 #include <core/ObjectAllocator.h>
 #include <core/MethodsCommon.h>


namespace wosh {
 namespace building {

 WOSH_REGISTER(wosh::building::GardenZone, "wosh::building::BuildingObject", _GardenZone_VERSION, _static_GardenZone )

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////// CONSTRUCTORS

GardenZone::GardenZone()
	: BuildingObject() {
	BuildingObject::setName( "wosh.building.GardenZone", _GET_Abs(Utilities::randomLong()) );
 }

void GardenZone::init() {
	Log(LOG_DEBUG, " Setting default properties and permissions.." );

	Log(LOG_DEBUG, " Registering methods.." );
	MethodWRESULTwSecurityToken* mmLightsTurnOn = Methods.create<MethodWRESULTwSecurityToken>( _GardenZone_METHOD_lights_on, "turn lights on", Permission::R_XR_XR__() );
	mmLightsTurnOn->setMethod( this, (MethodWRESULTwSecurityTokenPtr)&GardenZone::mmDoLightsTurnOn );

	MethodWRESULTwSecurityToken* mmLightsTurnOff = Methods.create<MethodWRESULTwSecurityToken>( _GardenZone_METHOD_lights_off, "turn lights off", Permission::R_XR_XR__() );
	mmLightsTurnOff->setMethod( this, (MethodWRESULTwSecurityTokenPtr)&GardenZone::mmDoLightsTurnOff );

	MethodWRESULTwSecurityToken* mmWaterOpen = Methods.create<MethodWRESULTwSecurityToken>( _GardenZone_METHOD_open, "turn lights off", Permission::R_XR_XR__() );
	mmWaterOpen->setMethod( this, (MethodWRESULTwSecurityTokenPtr)&GardenZone::mmDoWaterOpen );

	MethodWRESULTwSecurityToken* mmWaterClose = Methods.create<MethodWRESULTwSecurityToken>( _GardenZone_METHOD_close, "turn lights off", Permission::R_XR_XR__() );
	mmWaterClose->setMethod( this, (MethodWRESULTwSecurityTokenPtr)&GardenZone::mmDoWaterClose );

	BuildingObject::init();
 }

//////////////////////////////////////////////////////////////////////////////////////////////// CONSTRUCTORS
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////// PROCESS CHILD MESSAGES

void GardenZone::busMessageChild( const Message& childMessage ) {
	if ( childMessage.isEmpty() ) return;


 }

////////////////////////////////////////////////////////////////////////////////////// PROCESS CHILD MESSAGES
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////// GENERATED EVENTS

WRESULT GardenZone::mmDoLightsTurnOn( const SecurityToken* security ) {
	Log(LOG_INFO, ":mmDoLightsTurnOn()" );
	// state update is asynch. raised by Child-Device (as Fact)
	Request request( _Appliance_METHOD_on );
	request.setOmitResponse(true);
	BuildingObject::controlChildren( Light::className(), request, security );
	return WRET_OK;
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////

WRESULT GardenZone::mmDoLightsTurnOff( const SecurityToken* security ) {
	Log(LOG_INFO, ":mmDoLightsTurnOff()" );
	// state update is asynch. raised by Child-Device (as Fact)
	Request request( _Appliance_METHOD_off );
	request.setOmitResponse(true);
	BuildingObject::controlChildren( Light::className(), request, security );
	return WRET_OK;
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

WRESULT GardenZone::mmDoWaterOpen( const SecurityToken* security ) {
	Log(LOG_INFO, ":mmDoWaterOpen()" );
	// state update is asynch. raised by Child-Device (as Fact)
	Request request( _Sprinkler_METHOD_open );
	request.setOmitResponse(true);
	BuildingObject::controlChildren( Sprinkler::className(), request, security );
	return WRET_OK;
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////

WRESULT GardenZone::mmDoWaterClose( const SecurityToken* security ) {
	Log(LOG_INFO, ":mmDoWaterClose()" );
	// state update is asynch. raised by Child-Device (as Fact)
	Request request( _Sprinkler_METHOD_close );
	request.setOmitResponse(true);
	BuildingObject::controlChildren( Sprinkler::className(), request, security );
	return WRET_OK;
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

 }; // namespace building
}; // namespace wosh
